import axios from 'axios'

// 实例化axios实例
const request = axios.create({
    baseURL: '/api',
    timeout: 5000,
    headers: {
        "Content-Type": 'application/json;charset=utf-8'
    }
})

// 请求拦截
request.interceptors.request.use( config => {
    config.headers = config.headers || {}
    return config
})

// 响应拦截
request.interceptors.response.use( res => {
    const { code } = res.data
    // 发送请求失败
    if ( code !== 200 ){
        return Promise.reject(res.data)
    }else {
        return res.data
    }
})

export default request